package at.fhj.itm10.ticketmaster.beans;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import javax.annotation.ManagedBean;
import javax.annotation.PostConstruct;
import javax.faces.bean.RequestScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;

import org.primefaces.model.UploadedFile;

import at.fhj.itm10.ticketmaster.dao.DAOException;
import at.fhj.itm10.ticketmaster.entities.Address;
import at.fhj.itm10.ticketmaster.entities.Customer;
import at.fhj.itm10.ticketmaster.entities.Event;
import at.fhj.itm10.ticketmaster.entities.EventType;
import at.fhj.itm10.ticketmaster.services.AddressService;
import at.fhj.itm10.ticketmaster.services.EventService;
import at.fhj.itm10.ticketmaster.services.EventTypeService;
import at.fhj.itm10.ticketmaster.services.ServiceFactory;

@ManagedBean
@RequestScoped
public class EventBean {
	private EventService service;
	private EventTypeService eventTypeService;
	private List<EventType> eventtypes;
	private Event event;
	private Date start;
	private Date end;
	private EventType category;
	private List<Event> eventsList = new ArrayList<Event>();
	private List<Event> eventsl = new ArrayList<Event>();
	private ServiceFactory factory;
	/* Generate Adress-List */
	// Adress variablen
	private List<Address> adresslist = new ArrayList<Address>();
	private AddressService addressService;
	private Address address;
	private Address conv;
	private String name;
	private String street;
	private String zip;
	private String country;
	private String city;
	
	private List<Event> customersEventList = new ArrayList<Event>();

	// Event variablen
	private String eventName;
	private String date;
	private String enter;
	private String begin;
	private String description;
	private int eventType;
	private double ticketPrice; // singlePrice??
	private int standingAmount;
	private int seatAmount;
	private int logeAmount;
	private double standingPrice;
	private double seatPrice;
	private double logePrice;

	public int getStandingAmount() {
		return standingAmount;
	}

	public void setStandingAmount(int standingAmount) {
		this.standingAmount = standingAmount;
	}

	public int getSeatAmount() {
		return seatAmount;
	}

	public void setSeatAmount(int seatAmount) {
		this.seatAmount = seatAmount;
	}

	public int getLogeAmount() {
		return logeAmount;
	}

	public void setLogeAmount(int logeAmount) {
		this.logeAmount = logeAmount;
	}

	public double getStandingPrice() {
		return standingPrice;
	}

	public void setStandingPrice(double standingPrice) {
		this.standingPrice = standingPrice;
	}

	public double getSeatPrice() {
		return seatPrice;
	}

	public void setSeatPrice(double seatPrice) {
		this.seatPrice = seatPrice;
	}

	public double getLogePrice() {
		return logePrice;
	}

	public void setLogePrice(double logePrice) {
		this.logePrice = logePrice;
	}

	private UploadedFile flyer;
	private String imagePath;
	private Long eventId;

	// normal search
	private String namesearch;

	// extended search
	private String eventcount;

	/*
	 * List for putting events into HashMap HashMap for getting data into
	 * warenkorb.xhtml Authors: Martin Kropf, Wolfgang Schrattner, Reinhard
	 * Rebernig, Benjamin Hirt
	 */
	private HashMap<String, Event> events = new HashMap<String, Event>();
	private double singlePrice;

	public EventBean() {
		super();
		init();
	}

	// Reini braucht Preis, Title, Datum, Foto, ---> HashMap
	@PostConstruct
	public void init() {
		try {
			// getDAO
			factory = new ServiceFactory();

			initEvents();
			service = factory.getEventService();
			eventsList = service.findAll();

			addressService = factory.getAddressService();
			adresslist = addressService.findAll();

			eventcount = "Bisher noch keine Suchergebnisse";
			// insert test data
			// dao.insert(new
			// Event(1,"TestEvent1","2012-11-12 12:00:00",1,1,1,100.00,999,1,0));
			// dao.insert(new
			// Event(2,"TestEvent2","2012-11-13 12:00:00",1,1,1,50.00,888,1,0));

			// get test data
			// setEvent(dao.findById(1));

			// print test data to console
			// System.err.println(getEvent().toString());
			selectEventType();
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		// setEvent(new
		// Event(1,"TestEvent1","2012-11-12 12:00:00",1,1,1,100.00,999,1,0));

	}

	public String initForAdd() {
		
		long customerId;

		FacesContext context = FacesContext.getCurrentInstance();
		Customer customer = (Customer) context.getApplication().evaluateExpressionGet(context, "#{loginBean.getCustomer()}", Customer.class);

		if (customer == null) {
			ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
			try {
				ec.redirect(ec.getRequestContextPath() + "/login.xhtml");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			return null;

		}
		else {
			
			customerId = (Long) context.getApplication().evaluateExpressionGet(context, "#{loginBean.getCustomer().getId()}", Long.class);
			
			this.eventName = "";
			this.name = "";
			this.city = "";
			this.zip = "";
			this.street = "";
			this.country = "";
			
			this.date = "";
			
			this.enter = "";
			this.begin = "";

			this.description = "";
			this.ticketPrice = 0;
			this.standingPrice = 0;
			this.seatPrice = 0;
			this.logePrice = 0;
			this.standingAmount = 0;
			this.seatAmount = 0;
			this.logeAmount = 0;
			
		}

		return null;

	}

	public String initForEdit() throws ParseException {
		
		long customerId;

		if (eventId == null) {
			ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
			
			try {
				ec.redirect(ec.getRequestContextPath() + "/noevent.xhtml");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		try {
			service = factory.getEventService();
			event = service.findById(getEventId());
		} catch (DAOException e) {
			e.printStackTrace();
		}

		if (event == null) {
			ExternalContext ec = FacesContext.getCurrentInstance()
					.getExternalContext();
			try {
				ec.redirect(ec.getRequestContextPath() + "/noevent.xhtml");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		FacesContext context = FacesContext.getCurrentInstance();
		Customer customer = (Customer) context.getApplication().evaluateExpressionGet(context, "#{loginBean.getCustomer()}", Customer.class);

		if (customer == null) {
			ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
			
			try {
				ec.redirect(ec.getRequestContextPath() + "/login.xhtml");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			return null;
			
		}
		else {
			customerId = (Long) context.getApplication().evaluateExpressionGet(context, "#{loginBean.getCustomer().getId()}", Long.class);
		}
		
		if (event.getFkCustomerId() != customerId) {
			ExternalContext ec = FacesContext.getCurrentInstance()
					.getExternalContext();
			try {
				ec.redirect(ec.getRequestContextPath() + "/nopermission.xhtml");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			return null;
		}

		try {
			addressService = factory.getAddressService();
			address = addressService.findById(this.event.getFkAddressId());
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		this.eventName = event.getName();
		this.name = address.getName();
		this.city = address.getCity();
		this.zip = address.getZip();
		this.street = address.getStreet();
		this.country = address.getCountry();

		DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		DateFormat dateFormatter1 = new SimpleDateFormat("dd.MM.yyyy");
		Date dateFormat = dateFormatter.parse(event.getDateTime());
		this.date = dateFormatter1.format(dateFormat);

		DateFormat enterBeginFormatter = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		DateFormat enterBeginFormatter1 = new SimpleDateFormat("HH:mm");
		Date enterFormat = enterBeginFormatter.parse(event.getEnter());
		Date beginFormat = enterBeginFormatter.parse(event.getBegin());
		this.enter = enterBeginFormatter1.format(enterFormat);
		this.begin = enterBeginFormatter1.format(beginFormat);

		this.description = event.getDescription();
		this.ticketPrice = event.getTicketPrice();
		this.standingPrice = event.getStandingPrice();
		this.seatPrice = event.getSeatPrice();
		this.logePrice = event.getLogePrice();
		this.standingAmount = event.getStandingAmount();
		this.seatAmount = event.getSeatAmount();
		this.logeAmount = event.getLogeAmount();
		
		this.imagePath = event.getFlyer();

		return null;

	}

	public String initForList() throws ParseException {
		
		long customerId;

		FacesContext context = FacesContext.getCurrentInstance();
		Customer customer = (Customer) context.getApplication().evaluateExpressionGet(context, "#{loginBean.getCustomer()}", Customer.class);

		if (customer == null) {
			ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
			
			try {
				ec.redirect(ec.getRequestContextPath() + "/login.xhtml");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			return null;
			
		}
		else {
			customerId = (Long) context.getApplication().evaluateExpressionGet(context, "#{loginBean.getCustomer().getId()}", Long.class);
			service = factory.getEventService();
			customersEventList = service.findByCustomer(customerId);

			System.out.println("-----------> "+customerId);
			System.out.println("----------->"+customersEventList.size());	
		
		}
		
		return null;

	}
	
	/*
	 * writes data into HashMap
	 */
	public void initEvents() {

		Event e;

		for (int i = 0; i < eventsList.size(); i++) {
			e = eventsList.get(i);

			events.put((Long.toString(e.getId())), e);
		}

	}

	/*
	 * grab events for warenkorb.xhtml
	 */
	public Event showEventInfos(String id) throws DAOException {
		Event eventData = null;
		events = new HashMap<String, Event>();

		initEvents();
		service = factory.getEventService();
		eventsList = service.findAll();

		if (events.containsKey(id)) {
			eventData = events.get(id);

		} else {
			System.err.println("ERROR: No Event with this id -> " + id + "!");
		}

		return eventData;
	}

	/*
	 * get price for a single Event
	 */
	public double getTicketPrice(String id) {

		singlePrice = events.get(id).getTicketPrice();
		return singlePrice;

	}

	public void selectEventType() {

		try {
			eventTypeService = factory.getEventTypeService();
			setEventtypes(eventTypeService.findAll());
		} catch (DAOException e) {
			e.printStackTrace();
		}
	}
	
	public String cutFront(String txt, String part, int number) { 
		
        for (int i = 0; i < number; i++) { 
            txt = txt.substring(txt.indexOf(part) + 1, txt.length()); 
        } 
        
        return txt; 
        
    } 

	public String writeFlyerToFileSystem() {

		if (flyer != null) {

			ServletContext servletContext = (ServletContext) FacesContext
					.getCurrentInstance().getExternalContext().getContext();
			
			SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmss");
			
			String token = fmt.format(new Date());

			File f = new File(servletContext.getRealPath("/") + "img/flyers/"
					+ token + flyer.getFileName());

			InputStream fileInputStream = null;
			OutputStream fileOutputStream = null;

			try {

				fileInputStream = flyer.getInputstream();

				fileOutputStream = new FileOutputStream(f);

				byte buf[] = new byte[1024];
				int len;

				while ((len = fileInputStream.read(buf)) > 0) {
					fileOutputStream.write(buf, 0, len);
				}

			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			finally {
					try {

						if (fileInputStream != null) {
							fileInputStream.close();
						}

					} catch (Exception e2) {
						// TODO: handle exception
					}
			}

			String path = f.getPath();
			
			String relativePath = "/t" + this.cutFront(path, "ticketmaster", 1);
			
			return relativePath;
			
		}

		return "";
	}

	public void setFlyerPath(String path) {
		event.setFlyer(path);
	}

	public String saveNewEvent() throws ParseException {
		System.out.println("Dominik: saveNewEvent");
		// Todo: Eventuell Felder validieren
		Address address = new Address();
		address.setCity(this.getCity());
		address.setCountry(this.getCountry());
		address.setStreet(this.getStreet());
		address.setZip(this.getZip());
		address.setName(this.getName());
		// F
		System.out.println("Dominik: zuweisen: " + this.getEventName());

		try {
			addressService = factory.getAddressService();
			addressService.insertAddress(address);
			System.out.println("Dominik: wir sind im try-block");
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("Dominik: wir sind im catch-block");
		}
		System.out.println("Dominik: nach insert adress");

		event = new Event();
		event.setFkAddressId(address.getId());

		// Select event type
		event.setFkEventtypeId(eventType);
		// selectEventType();

		// Write flyer to file system and set path
		
		if(!this.writeFlyerToFileSystem().equals("")) {
			this.setFlyerPath(this.writeFlyerToFileSystem());
		}

		// System.out.println("Dominik: vor setFkCustomerId" + customerId);
		FacesContext context = FacesContext.getCurrentInstance();
		int customerId = (Integer) context.getApplication()
				.evaluateExpressionGet(context,
						"#{loginBean.getCustomer().getId()}", Integer.class);
		event.setFkCustomerId((int) customerId);

		System.out.println("Dominik: Customer = "
				+ context.getApplication().evaluateExpressionGet(context,
						"#{loginBean.getCustomer()}", Customer.class));

		System.out.println("Dominik: CustomerID" + customerId);

		event.setName(this.getEventName());
		// Todo: beginn - was ist das richitge Beginn?
		// Todo: einlass = enter?

		// Date Formatter für das Datum in Datetime
		DateFormat dateFormatter = new SimpleDateFormat("dd.MM.yyyy");
		DateFormat dateFormatter1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date dateRes = dateFormatter.parse(date);
		// dateFormatter1.format(dateRes);

		// Date Formatter für Eintritt in timestamp
		DateFormat enterBeginFormatter = new SimpleDateFormat("HH:mm");
		DateFormat enterBeginFormatter1 = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		Date eintritt = enterBeginFormatter.parse(enter);
		enterBeginFormatter1.format(eintritt);

		// Date Formatter für Begin in timestamp
		Date beginn = enterBeginFormatter.parse(begin);
		enterBeginFormatter1.format(beginn);

		// @Benjamin - temporär da datepicker bei mir nicht funktioniert hat
		if (date == null) {
			event.setDateTime(dateFormatter.format(new Date()));
		} else {
			event.setDateTime(dateFormatter1.format(dateRes));
		}
		System.out.println("Dominik: eventBean" + event.getDateTime());

		event.setEnter(enterBeginFormatter1.format(eintritt));
		event.setBegin(enterBeginFormatter1.format(beginn));
		event.setDescription(this.getDescription());
		event.setTicketPrice(this.getTicketPrice());
		event.setStandingPrice(this.getStandingPrice());
		event.setSeatPrice(this.getSeatPrice());
		event.setLogePrice(this.getLogePrice());
		event.setStandingAmount(this.getStandingAmount());
		event.setSeatAmount(this.getSeatAmount());
		event.setLogeAmount(this.getLogeAmount());

		System.out.println("Dominik: vor Insert Event" + event.getFkAddressId()
				+ ":" + event.getFkCustomerId() + ":"
				+ event.getFkEventtypeId());

		try {
			service = factory.getEventService();
			service.insertEvent(event);
		} catch (DAOException e1) {
			e1.printStackTrace();
			return "Speichernfehlgeschlagen";
		}
		System.out.println("Dominik: nach Insert Event");
		return "SpeichernErfolgreich";

	}

	public String getEventName() {
		return eventName;
	}

	public void setEventName(String eventName) {
		System.out.println("Dominik: setEventName: " + eventName);
		this.eventName = eventName;
	}

	public int getEventType() {
		return eventType;
	}

	public void setEventType(int eventType) {
		this.eventType = eventType;
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public String getEnter() {
		return enter;
	}

	public void setEnter(String enter) {
		this.enter = enter;
	}

	public String getBegin() {
		return begin;
	}

	public void setBegin(String begin) {
		this.begin = begin;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public double getTicketPrice() {
		return ticketPrice;
	}

	public void setTicketPrice(double ticketPrice) {
		this.ticketPrice = ticketPrice;
	}

	public UploadedFile getFlyer() {
		return flyer;
	}

	public void setFlyer(UploadedFile flyer) {
		this.flyer = flyer;
	}

	public Long getEventId() {
		return eventId;
	}

	public void setEventId(Long eventId) {
		this.eventId = eventId;
	}

	public String editEvent() throws ParseException {

		address.setCity(this.getCity());
		address.setCountry(this.getCountry());
		address.setStreet(this.getStreet());
		address.setZip(this.getZip());
		address.setName(this.getName());
		address.setId(event.getFkAddressId());

		try {
			addressService = factory.getAddressService();
			addressService.updateAddress(address);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		event.setFkAddressId(address.getId());

		// Select event type
		event.setFkEventtypeId(eventType);
		// selectEventType();

		// Write flyer to file system and set path

		if(!this.writeFlyerToFileSystem().equals("")) {
			this.setFlyerPath(this.writeFlyerToFileSystem());
		}

		FacesContext context = FacesContext.getCurrentInstance();

		int customerId = (Integer) context.getApplication()
				.evaluateExpressionGet(context,
						"#{loginBean.getCustomer().getId()}", Integer.class);
		event.setFkCustomerId((int) customerId);
		System.out.println("Dominik: CustomerID 2222222" + customerId);

		// Syso Wolfgang
		System.out.println("Dominik: Customer = "
				+ context.getApplication().evaluateExpressionGet(context,
						"#{loginBean.getCustomer()}", Customer.class));

		event.setName(this.getEventName());


		// Date Formatter für das Datum in Datetime
		DateFormat dateFormatter = new SimpleDateFormat("dd.MM.yyyy");
		DateFormat dateFormatter1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date dateRes = dateFormatter.parse(date);
		dateFormatter1.format(dateRes);

		// Date Formatter für Eintritt in timestamp
		DateFormat enterBeginFormatter = new SimpleDateFormat("HH:mm");
		DateFormat enterBeginFormatter1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date eintritt = enterBeginFormatter.parse(enter);
		enterBeginFormatter1.format(eintritt);

		// Date Formatter für Begin in timestamp
		Date beginn = enterBeginFormatter.parse(begin);
		enterBeginFormatter1.format(beginn);

		event.setEnter(enterBeginFormatter1.format(eintritt));
		event.setBegin(enterBeginFormatter1.format(beginn));
		event.setDescription(this.getDescription());
		event.setTicketPrice(this.getTicketPrice());
		event.setStandingPrice(this.getStandingPrice());
		event.setSeatPrice(this.getSeatPrice());
		event.setLogePrice(this.getLogePrice());
		event.setStandingAmount(this.getStandingAmount());
		event.setSeatAmount(this.getSeatAmount());
		event.setLogeAmount(this.getLogeAmount());
		event.setId(this.eventId);

		try {
			service = factory.getEventService();
			service.updateEvent(event);
		} catch (DAOException e1) {
			// TODO Auto-generated catch block
			return "Speichernfehlgeschlagen";
		}

		return "SpeichernErfolgreich";

	}

	/*
	 * Extended Search Author: Gerald Hambrosch
	 */

	// Method to call EventDAO and perform extended Search
	public void doExtendedSearch() throws DAOException, SQLException {

		refresh();
		this.eventsl = service.doExtendedSearch(address, category, start, end);
		
			if (eventsl.size() != 0) {
				eventcount = String.valueOf(eventsl.size())
						+ " Ergebnisse gefunden";
				if (eventsl.size() == 1) {
					eventcount = String.valueOf(eventsl.size())
							+ " Ergebnis gefunden";
				}
				if (eventsl.size() > 1) {
					eventcount = String.valueOf(eventsl.size())
							+ " Ergebnisse gefunden";
				}
			}
	
			else {
				eventcount = "Keine Ergebnisse gefunden";
			}
		
	}
	/*
		*/

	// method to delete search results
	public void resetSearch() {
		if (!eventsl.isEmpty()) {
			eventsl.clear();
			namesearch = null;
			start = null;
			end = null;
			address = null;
			category = null;
			eventcount = "Bisher noch keine Suchergebnisse";
		}

	}

	/*
	 * normal search Author: Christopher Barilich
	 */

	public void doNormalSearch() throws DAOException, SQLException {

		// clear last search
		//resetSearch();

		if (namesearch.equals("")) 
		{ // empty searchbox -> empty string
			eventcount = "Keine Ergebnisse gefunden";
		}
		else
		{
			// add events to eventslist
			service = factory.getEventService();
			this.eventsl = service.doNormalSearch(getNamesearch());
			

				
			}
			if (eventsl.size() != 0) {
				eventcount = String.valueOf(eventsl.size())
						+ " Ergebnisse gefunden";
				if (eventsl.size() == 1) {
					eventcount = String.valueOf(eventsl.size())
							+ " Ergebnis gefunden";
				}
				if (eventsl.size() > 1) {
					eventcount = String.valueOf(eventsl.size())
							+ " Ergebnisse gefunden";
				}
			}

			else {
				eventcount = "Keine Ergebnisse gefunden";
			}

	}

	

	public void refresh()
	{
		service = factory.getEventService();
	}

	  
	public Event getEvent() {
		return event;
	}

	public void setEvent(Event event) {
		this.event = event;
	}

	public Date getStart() {
		return start;
	}

	public void setStart(Date start) {
		this.start = start;
	}

	public Date getEnd() {
		return end;
	}

	public void setEnd(Date end) {
		this.end = end;
	}

	public EventType getCategory() {
		return category;
	}

	public void setCategory(EventType category) {
		this.category = category;
	}

	public List<Event> getEventsl() {
		return eventsl;
	}

	public void setEventsl(List<Event> eventsl) {
		this.eventsl = eventsl;
	}

	public List<Address> getAdresslist() {
		return adresslist;
	}

	public void setAdresslist(List<Address> adresslist) {
		this.adresslist = adresslist;
	}

	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getStreet() {
		return street;
	}

	public void setStreet(String street) {
		this.street = street;
	}

	public String getZip() {
		return zip;
	}

	public void setZip(String zip) {
		this.zip = zip;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getNamesearch() {
		return namesearch;
	}

	public void setNamesearch(String namesearch) throws DAOException,
			SQLException {
		this.namesearch = namesearch;

		doNormalSearch();

	}

	public Address getConv() {
		return conv;
	}

	public void setConv(Address conv) {
		this.conv = conv;
	}

	public String getEventcount() {
		return eventcount;
	}

	public void setEventcount(String eventcount) {
		this.eventcount = eventcount;
	}

	// returns event infos and if the event id is not valid this function
	// returns a dummy event

	public Event showEventInfosWithDummy(String id) throws DAOException {
		Event eventData = null;
		events = new HashMap<String, Event>();

		initEvents();

		if (events.containsKey(id)) {
			eventData = events.get(id);

		} else {
			System.err.println("ERROR: No Event with this id -> " + id + "!");
			eventData = new Event();
			eventData.setName("This event is not available");
			eventData.setTicketPrice(0);
		}

		return eventData;
	}

	public List<EventType> getEventtypes() {
		return eventtypes;
	}

	public void setEventtypes(List<EventType> eventtypes) {
		this.eventtypes = eventtypes;
	}

	public EventService getService() {
		return service;
	}

	public void setService(EventService service) {
		this.service = service;
	}

	public EventTypeService getEventTypeService() {
		return eventTypeService;
	}

	public void setEventTypeService(EventTypeService eventTypeService) {
		this.eventTypeService = eventTypeService;
	}

	public AddressService getAddressService() {
		return addressService;
	}

	public void setAddressService(AddressService addressService) {
		this.addressService = addressService;
	}

	public ServiceFactory getFactory() {
		return factory;
	}

	public void setFactory(ServiceFactory factory) {
		this.factory = factory;
	}

	public List<Event> getCustomersEventList() {
		return customersEventList;
	}

	public void setCustomersEventList(List<Event> customersEventList) {
		this.customersEventList = customersEventList;
	}

	public String getImagePath() {
		return imagePath;
	}

	public void setImagePath(String imagePath) {
		this.imagePath = imagePath;
	}
		
}
